/*
 * =====================================================================================
 *
 *       Filename:  timeOut.cpp
 *
 *    Description:  
 *
 *        Version:  1.0
 *        Created:  07/04/15 20:28:13
 *       Revision:  none
 *       Compiler:  gcc
 *
 *         Author:  Andy (gk), andy_y_li@163.com
 *        Company:  RD
 *
 * =====================================================================================
 */

#include "timeOut.h"
#include <sys/time.h>

#define SECTOMSEC  1000     /* seconds to millisecond*/
#define USECTOMSEC 1000     // microseconds to millisecond

TimeOut::TimeOut(long timeMs)
{
    struct timeval now;
    gettimeofday(&now, NULL);
    this->when = now.tv_sec * SECTOMSEC + now.tv_usec / USECTOMSEC +timeMs;
}

bool TimeOut::isTimeOut()
{
    struct timeval now;
    gettimeofday(&now, NULL);
    bool retValue = false;
    if (now.tv_sec * SECTOMSEC + now.tv_usec / USECTOMSEC > this->when) {
        retValue = true;
    }
    return retValue;
}

